
/**
  ******************************************************************************
  * Copyright 2021 The Microbee Authors. All Rights Reserved.
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  * 
  * http://www.apache.org/licenses/LICENSE-2.0
  * 
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  * 
  * @file       sim_ship.h
  * @author     baiyang
  * @date       2022-11-30
  ******************************************************************************
  */

#pragma once

#ifdef __cplusplus
extern "C"{
#endif

/*----------------------------------include-----------------------------------*/
#include <stdint.h>
#include <stdbool.h>

#include <rtconfig.h>

#include <common/gp_defines.h>
#include <common/utility/mb_socket.h>
#include <common/location/location.h>
#include <common/gp_math/gp_mathlib.h>
/*-----------------------------------macro------------------------------------*/
#ifndef AP_SIM_SHIP_ENABLED
#define AP_SIM_SHIP_ENABLED (CONFIG_HAL_BOARD == HAL_BOARD_SITL_WIN)
#endif

#if AP_SIM_SHIP_ENABLED
/*----------------------------------typedef-----------------------------------*/
typedef struct Ship* ship_t;
typedef const struct Ship* ship_const_t;

typedef struct sim_ship* sim_ship_t;
typedef const struct sim_ship* sim_ship_const_t;

struct Ship {
    Vector2f_t position;
    float heading_deg;
    float yaw_rate;
    float speed;
    sim_ship_t sim;
};

struct sim_ship {
    Param_int8 enable;
    Param_float speed;
    Param_float path_size;
    Param_float deck_size;
    Param_int8 sys_id;
    Param_Vector3f offset;

    Location home;
    const char *target_address;        // default, "127.0.0.1"
    uint16_t target_port;              // default, 5762;

    bool initialised;
    struct Ship ship;
    uint32_t last_update_us;

    // reporting period in ms
    float reporting_period_ms;         // default, 200;
    uint32_t last_report_ms;
    uint32_t last_heartbeat_ms;

    struct mb_socket mav_socket;       // default, false;
    bool mavlink_connected;
};
/*----------------------------------variable----------------------------------*/

/*-------------------------------------os-------------------------------------*/

/*----------------------------------function----------------------------------*/
void ship_update(ship_t ship, float delta_t);

void sim_ship_ctor(sim_ship_t simship);
Vector2f_t sim_ship_get_ground_speed_adjustment(sim_ship_t simship, const Location *loc, float *yaw_rate);
/*------------------------------------test------------------------------------*/
#endif  // AP_SIM_SHIP_ENABLED

#ifdef __cplusplus
}
#endif



